﻿using App.Forms;
using Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace App
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            panel2.Visible = false;
            panel1.Visible = true;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //language=english
            panel1.Visible = false;
            panel2.Visible = true;
            this.Text = "Enter PIN";
        }

        private void btnEnterPIN_Click(object sender, EventArgs e)
        {
            
            try
            {
                TaskManager tm = new TaskManager();
                Model.Account account = new Model.Account() { PIN = int.Parse(txtPIN.Text) };
                if (!tm.AuthenticateUser(account))
                {
                    txtPIN.Text = string.Empty;
                    MessageBox.Show("Authentication failed.. Please check your PIN",
                                    "Invalid PIN",
                                    MessageBoxButtons.OK);
                    return;
                }


            }
            catch (Exception ex)
            {

                return;
            }
            this.Hide();
            var frm = new Main();
            frm.Closed += (s, args) => this.Close();
            frm.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("SORRY.. Currently our system does not support Nepali language",
                                   "Language not supported",
                                   MessageBoxButtons.OK);
            return;
        }

        private void btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            txtPIN.Text += btn.Text;
           
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtPIN.Text = string.Empty;
        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            txtPIN.Text = txtPIN.Text.Substring(0, txtPIN.Text.Length - 1);
        }
    }
}
